﻿using RAP.Framework.Libary.DomTemplateBuilder.Attributes;
using RAP.Framework.Libary.DomTemplateBuilder.Handler.Parameter;
using RAP.Framework.Libary.Utils;

namespace RAP.Framework.Libary.DomTemplateBuilder.Element
{
	/// <summary>
	/// 参数节点
	/// </summary>
	[TagHandler( typeof( ParameterHandler ) )]
    public class ParameterElement : PropertyElement
    {
        /// <summary>
        /// 
        /// </summary>
        public ParameterElement ( )
            : base ( )
        {
            this.ValueStyle = PropertyValueStyles.Parent;
        }

        protected string _alias = string.Empty;
        /// <summary>
        /// 参数的别名
        /// </summary>
		public virtual string Alias
        {
            get
            {
                if ( _alias.IsNullOrEmpty() )
                {
                    _alias = this.ToString( "Alias", string.Empty );
                }
                return _alias;
            }
            set
            {
                this[ "Alias" ] = _alias = value;
            }
        }

        private ConvertableTypes? _type = null;
        /// <summary>
        /// 
        /// </summary>
        public ConvertableTypes? Type
        {
            get
            {
                if ( _type == null )
                {
                    string t = this.ToString ( "Type", "String" );
                    switch ( t )
                    {
                        case "DateTime":
                            _type = ConvertableTypes.DateTime;
                            break;

                        case "Number":
                            _type = ConvertableTypes.Number;
                            break;

                        case "Int32":
                            _type = ConvertableTypes.Int32;
                            break;

                        case "Boolean":
                            _type = ConvertableTypes.Boolean;
                            break;

                        default:
                            _type = ConvertableTypes.String;
                            break;
                    }
                }
                return _type;
            }
            set
            {
                this[ "Type" ] = value;
            }
        }
    }
}
